﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Abp.Authorization;
using SFGX.Mango.Authorization;
using SFGX.Mango.BoxUses.Dto;
using SFGX.Mango.ExpressPersons;

namespace SFGX.Mango.BoxUses
{
	[AbpAuthorize(PermissionNames.Pages_BoxUses)]
	public class BoxUseAppService : MangoAppServiceBase, IBoxUseAppService
	{
		private readonly IBoxUseManager _boxUseManager;
		private readonly IExpressPersonManager _expressPersonManager  ;

		public BoxUseAppService(IBoxUseManager  boxUseManager, IExpressPersonManager expressPersonManager) {
			_boxUseManager = boxUseManager;
			_expressPersonManager = expressPersonManager;
		}

		public async Task BoxHandlerAsync(int id, string openId, int boxUsed)
		{
			await _boxUseManager.BoxHandlerAsync(id, openId, boxUsed);
		}

		public async Task BuyBoxAsync(BuyBoxInput input)
		{
			var expressPerson =await _expressPersonManager.GetAsync(input.OpenId);

			await _boxUseManager.BuyBoxAsync( new BoxUse {
				 BoxReceiveCount= input.BoxReceiveCount,
				  BoxType=input.BoxType,
				 ExpressPersonId = expressPerson.Id, 
				    
			});
		}

		public async Task<IReadOnlyList<BoxUse>> GetListAsync(string openId)
		{
			return await _boxUseManager.GetListAsync(openId);
		}
	}
}
